package day07;

public class 买卖芯片的最佳时机 {
    public int bestTiming(int[] prices) {
        int n = prices.length;
        int minprice = Integer.MAX_VALUE;
        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (prices[i] < minprice) {
                minprice = prices[i];
            } else if (prices[i] - minprice > ret) {
                ret = prices[i] - minprice;
            }
        }
        return ret;
    }
}
